CREATE TABLE [dbo].[DnnProduct_Files]
(
[FileId] [int] NOT NULL IDENTITY(1, 1),
[PortalId] [int] NULL,
[FileName] [nvarchar] (246) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Extension] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Size] [int] NOT NULL,
[Width] [int] NULL,
[Height] [int] NULL,
[ContentType] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Folder] [nvarchar] (246) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FolderID] [int] NOT NULL,
[Content] [image] NULL,
[CreatedByUserID] [int] NULL,
[CreatedOnDate] [datetime] NULL,
[LastModifiedByUserID] [int] NULL,
[LastModifiedOnDate] [datetime] NULL,
[UniqueId] [uniqueidentifier] NOT NULL CONSTRAINT [DF_DnnProduct_Files_UniqueId] DEFAULT (newid()),
[VersionGuid] [uniqueidentifier] NOT NULL CONSTRAINT [DF_DnnProduct_Files_VersionGuid] DEFAULT (newid()),
[SHA1Hash] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LastModificationTime] [datetime] NOT NULL CONSTRAINT [DF__DnnProduc__LastM__4E347170] DEFAULT (getdate())
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_Files] ADD CONSTRAINT [PK_DnnProduct_File] PRIMARY KEY CLUSTERED  ([FileId]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_Files] ADD CONSTRAINT [IX_DnnProduct_FileName] UNIQUE NONCLUSTERED  ([FolderID], [FileName]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_Files] ADD CONSTRAINT [IX_FileName] UNIQUE NONCLUSTERED  ([FolderID], [FileName]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_Files] ADD CONSTRAINT [IX_DnnProduct_Files_UniqueId] UNIQUE NONCLUSTERED  ([UniqueId]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_Files] ON [dbo].[DnnProduct_Files] ([PortalId]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_Files] ADD CONSTRAINT [FK_DnnProduct_Files_DnnProduct_Folders] FOREIGN KEY ([FolderID]) REFERENCES [dbo].[DnnProduct_Folders] ([FolderID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[DnnProduct_Files] ADD CONSTRAINT [FK_DnnProduct_Files_DnnProduct_Portals] FOREIGN KEY ([PortalId]) REFERENCES [dbo].[DnnProduct_Portals] ([PortalID])
GO
